package com.clstu.staticmathod_.interface_;

public class InterfacePolyArr {
    public static void main(String[] args) {
         Usb[] usb = new Usb[2];  //多态接口数组，跟多态数组一样
         usb[0]=new Phone_();
         usb[1]=new Camera_();     //向上转型
        for (int i = 0; i < usb.length; i++) {
            usb[i].work();          //调用函数遵循动态绑定机制
            if(usb[i] instanceof Phone_){//要调用特殊方法，需要向下转型
                ((Phone_)usb[i]).call();
            }
        }
    }
}
interface Usb{
    void work();
}

class Phone_ implements Usb{
    @Override
    public void work() {
        System.out.println("Phone is working");
    }

    public void call(){
        System.out.println("这是电话，可以打电话哟");
    }

}

class Camera_ implements Usb{
    @Override
    public void work() {
        System.out.println("Camera is working...");
    }



}